package com.linzelin.controller;

import com.linzelin.po.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
public class AjaxController {

    @RequestMapping("/test")
    @ResponseBody
    public String test() {
        return "hello";
    }


    @RequestMapping("/a")
    @ResponseBody
    public void a(String name, HttpServletResponse response) throws IOException {
        System.out.println("name=" + name);
        if ("lin".equals(name)) {
            response.getWriter().print("true");
            //打印一个true在窗口上
        } else {
            response.getWriter().print("false");
        }
    }

    @RequestMapping("/a2")
    @ResponseBody
    public List<User> a2() {
        List<User> list = new ArrayList<>();
        //添加一个user
        list.add(new User("林先生", 12, "男"));
        list.add(new User("林女士", 13, "女"));
        return list;
    }

    @RequestMapping("/a3")
    @ResponseBody
    public Boolean examine(String name) {
        if ("lin".equals(name)) {
            return true;
        } else {
            return false;
        }
    }

}